home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / x / volume7 / xtiff / patch1 < prev    next >
Encoding:
Text File  |  1990-05-17  |  25.2 KB  |  723 lines

  1. Path: uunet!snorkelwacker!apple!sun-barr!newstop!sun!decpa.pa.dec.com
  2. From: dbs@decpa.pa.dec.com (dan sears)
  3. Newsgroups: comp.sources.x
  4. Subject: v07i054: xtiff, Patch1, Part01/01
  5. Message-ID: <135893@sun.Eng.Sun.COM>
  6. Date: 17 May 90 20:44:27 GMT
  7. Sender: news@sun.Eng.Sun.COM
  8. Lines: 712
  9. Approved: argv@sun.com
  10.  
  11. Submitted-by: dbs@decpa.pa.dec.com (dan sears)
  12. Posting-number: Volume 7, Issue 54
  13. Archive-name: xtiff/patch1
  14. Patch-To: xtiff: Volume 7, Issue 37 (5/12/90)
  15.  
  16. These patches correct a few minor bugs in the original release of xtiff
  17. dealing with different visual types.  The routines CreateXImage() and
  18. GetTIFFImage() are where these problems reside and are resolved.  Basically,
  19. the available documentation does not provide enough information to figure
  20. out the many to many mapping between a complex TIFF image and the numerous
  21. configurations of X visuals.  We would like to write some magic code in
  22. CreateXImage which worked for all cases on all servers but it isn't that
  23. simple.
  24.  
  25. NB: xtiff.c requires libtiff version 2.2, which is currently in beta test.
  26. --Dan Sears
  27.  
  28.  
  29. -- cut here (patch.01) --
  30. diff -r -c rev1/Imakefile rev2/Imakefile
  31. *** rev1/Imakefile    Wed May 16 12:33:35 1990
  32. --- rev2/Imakefile    Thu May 17 11:18:37 1990
  33. ***************
  34. *** 17,28 ****
  35.   AllTarget(xtiff)
  36.   NormalProgramTarget(xtiff, $(OBJS), /* */, $(LOCAL_LIBRARIES), /* */)
  37.   DependTarget()
  38. - proto::
  39. -     cproto $(TIFF_INCLUDES) xtiff.c > xtiff.proto
  40. - lint::
  41. -     lint $(TIFF_INCLUDES) xtiff.c -lX11 -lm
  42. - tags::
  43. -     ctags xtiff.c
  44. --- 17,19 ----
  45. diff -r -c /dev/null rev2/patchlevel.h
  46. *** /dev/null    Wed May 16 23:18:29 1990
  47. --- patchlevel.h    Thu May 17 11:16:26 1990
  48. ***************
  49. *** 0 ****
  50. --- 1 ----
  51. + #define PATCHLEVEL 1
  52. diff -r -c rev1/xtiff.c rev2/xtiff.c
  53. *** rev1/xtiff.c    Wed May 16 12:33:38 1990
  54. --- rev2/xtiff.c    Thu May 17 11:21:23 1990
  55. ***************
  56. *** 1,9 ****
  57.   /*
  58.    * xtiff - view a TIFF file in an X window
  59.    *
  60. !  * Dan Sears - May 7, 1990
  61.    * Chris Sears
  62.    *
  63.    * Copyright 1990 by Digital Equipment Corporation, Maynard, Massachusetts.
  64.    *
  65.    *                        All Rights Reserved
  66. --- 1,14 ----
  67.   /*
  68.    * xtiff - view a TIFF file in an X window
  69.    *
  70. !  * Dan Sears
  71.    * Chris Sears
  72.    *
  73. +  * Revsion 1.1  90/05/16
  74. +  *      Fixed a few minor bugs.
  75. +  * Revsion 1.0  90/05/07
  76. +  *      Initial release.
  77. +  *
  78.    * Copyright 1990 by Digital Equipment Corporation, Maynard, Massachusetts.
  79.    *
  80.    *                        All Rights Reserved
  81. ***************
  82. *** 42,49 ****
  83.    * default TIFF and X orientation.  Other orientations will be
  84.    * displayed incorrectly.
  85.    *
  86. !  * Only TIFFTAG_BITSPERSAMPLE values that are powers of 2 (1, 2, 4 or 8)
  87. !  * are supported.
  88.    */
  89.   
  90.   #include <math.h>
  91. --- 47,56 ----
  92.    * default TIFF and X orientation.  Other orientations will be
  93.    * displayed incorrectly.
  94.    *
  95. !  * There is no support for or use of 3/3/2 DirectColor visuals.
  96. !  * TIFFTAG_MINSAMPLEVALUE and TIFFTAG_MAXSAMPLEVALUE are not supported.
  97. !  *
  98. !  * Only TIFFTAG_BITSPERSAMPLE values that are 1, 2, 4 or 8 are supported.
  99.    */
  100.   
  101.   #include <math.h>
  102. ***************
  103. *** 82,88 ****
  104.   GC                  xWinGc, xBitmapGc;
  105.   XGCValues           xGcValues;
  106.   int                 xScreen, xSyncFlag = False, xImageDepth, xNVisuals,
  107. !                     xPixmapFlag = True;
  108.   char *              xGeometry = NULL, *xDisplayName = NULL;
  109.   XVisualInfo *       xVisualList;
  110.   
  111. --- 89,95 ----
  112.   GC                  xWinGc, xBitmapGc;
  113.   XGCValues           xGcValues;
  114.   int                 xScreen, xSyncFlag = False, xImageDepth, xNVisuals,
  115. !                     xPixmapFlag = True, xRedMask, xGreenMask, xBlueMask;
  116.   char *              xGeometry = NULL, *xDisplayName = NULL;
  117.   XVisualInfo *       xVisualList;
  118.   
  119. ***************
  120. *** 92,99 ****
  121.   TIFF *              tfFile;
  122.   u_short             tfBitsPerSample, tfSamplesPerPixel, tfPlanarConfiguration,
  123.                       tfPhotometricInterpretation, tfGrayResponseUnit,
  124. !                     tfImageDepth, tfImageWidth, tfImageHeight, tfBytesPerRow,
  125. !                     tfFillOrder;
  126.   int                 tfDirectory = 0;
  127.   double              tfUnitMap, tfGrayResponseUnitMap[] = {
  128.                           -1, -10, -100, -1000, -10000, -100000
  129. --- 99,105 ----
  130.   TIFF *              tfFile;
  131.   u_short             tfBitsPerSample, tfSamplesPerPixel, tfPlanarConfiguration,
  132.                       tfPhotometricInterpretation, tfGrayResponseUnit,
  133. !                     tfImageDepth, tfImageWidth, tfImageHeight, tfBytesPerRow;
  134.   int                 tfDirectory = 0;
  135.   double              tfUnitMap, tfGrayResponseUnitMap[] = {
  136.                           -1, -10, -100, -1000, -10000, -100000
  137. ***************
  138. *** 122,129 ****
  139.       programName = argv[0];
  140.   
  141.       if (argc == 1) {
  142. !         fprintf(stderr, "Usage: %s file\n", programName);
  143. !         fprintf(stderr, "options:\n");
  144.           fprintf(stderr, "    [-directory directory]\n");
  145.           fprintf(stderr, "    [-display display]\n");
  146.           fprintf(stderr, "    [-gamma gamma]\n");
  147. --- 128,134 ----
  148.       programName = argv[0];
  149.   
  150.       if (argc == 1) {
  151. !         fprintf(stderr, "Usage: %s file\noptions:\n", programName);
  152.           fprintf(stderr, "    [-directory directory]\n");
  153.           fprintf(stderr, "    [-display display]\n");
  154.           fprintf(stderr, "    [-gamma gamma]\n");
  155. ***************
  156. *** 182,189 ****
  157.       /*
  158.        * If the following tags aren't present then use the TIFF defaults.
  159.        */
  160. -     if (!TIFFGetField(tfFile, TIFFTAG_FILLORDER, &tfFillOrder))
  161. -         tfFillOrder = FILLORDER_MSB2LSB;
  162.       if (!TIFFGetField(tfFile, TIFFTAG_BITSPERSAMPLE, &tfBitsPerSample))
  163.           tfBitsPerSample = 1;
  164.       if (!TIFFGetField(tfFile, TIFFTAG_SAMPLESPERPIXEL, &tfSamplesPerPixel))
  165. --- 187,192 ----
  166. ***************
  167. *** 200,205 ****
  168. --- 203,209 ----
  169.       dRed = (double *) malloc(colormapSize * sizeof(double));
  170.       dGreen = (double *) malloc(colormapSize * sizeof(double));
  171.       dBlue = (double *) malloc(colormapSize * sizeof(double));
  172. +     MCHECK(dRed); MCHECK(dGreen); MCHECK(dBlue);
  173.   
  174.       /*
  175.        * If TIFFTAG_PHOTOMETRIC is not present then assign a reasonable default.
  176. ***************
  177. *** 306,314 ****
  178.   }
  179.   
  180.   /*
  181. !  * Many programs get TIFF colormaps wrong.  They use 8-bit colormaps instead
  182. !  * of 16-bit colormaps.  This function is a heuristic to detect and correct
  183. !  * that problem.
  184.    */
  185.   void
  186.   CheckAndCorrectColormap()
  187. --- 310,317 ----
  188.   }
  189.   
  190.   /*
  191. !  * Many programs get TIFF colormaps wrong.  They use 8-bit colormaps instead of
  192. !  * 16-bit colormaps.  This function is a heuristic to detect and correct this.
  193.    */
  194.   void
  195.   CheckAndCorrectColormap()
  196. ***************
  197. *** 334,348 ****
  198.       register int i;
  199.   
  200.       for (i = 0; i < colormapSize; i++) {
  201. !         if ((tfPhotometricInterpretation == PHOTOMETRIC_MINISWHITE)
  202.               && (i == colormapSize - 1))
  203.               redMap[i] = greenMap[i] = blueMap[i] = 0;
  204. !         else if (i == 0)
  205. !             redMap[i] = greenMap[i] = blueMap[i] = 0;
  206. !         redMap[i] = ROUND((pow(dRed[i] / 65535.0, 1.0 / dGamma) * 65535.0));
  207. !         greenMap[i] = ROUND((pow(dGreen[i] / 65535.0, 1.0 / dGamma) * 65535.0));
  208. !         blueMap[i] = ROUND((pow(dBlue[i] / 65535.0, 1.0 / dGamma) * 65535.0));
  209.       }
  210.   
  211.       free(dRed); free(dGreen); free(dBlue);
  212. --- 337,352 ----
  213.       register int i;
  214.   
  215.       for (i = 0; i < colormapSize; i++) {
  216. !         if (((tfPhotometricInterpretation == PHOTOMETRIC_MINISWHITE)
  217.               && (i == colormapSize - 1))
  218. +             || ((tfPhotometricInterpretation == PHOTOMETRIC_MINISBLACK)
  219. +             && (i == 0)))
  220.               redMap[i] = greenMap[i] = blueMap[i] = 0;
  221. !         else {
  222. !             redMap[i] = ROUND((pow(dRed[i] / 65535.0, 1.0 / dGamma) * 65535.0));
  223. !             greenMap[i] = ROUND((pow(dGreen[i] / 65535.0, 1.0 / dGamma) * 65535.0));
  224. !             blueMap[i] = ROUND((pow(dBlue[i] / 65535.0, 1.0 / dGamma) * 65535.0));
  225. !         }
  226.       }
  227.   
  228.       free(dRed); free(dGreen); free(dBlue);
  229. ***************
  230. *** 355,361 ****
  231.       char **xargv;
  232.   {
  233.       register int i;
  234. !     int win_x = 0, win_y = 0, win_width, win_height;
  235.       u_int border_width = 3;
  236.       XSizeHints size_hints;
  237.       XSetWindowAttributes window_attributes;
  238. --- 359,365 ----
  239.       char **xargv;
  240.   {
  241.       register int i;
  242. !     int win_x = 0, win_y = 0, win_w = tfImageWidth, win_h = tfImageHeight;
  243.       u_int border_width = 3;
  244.       XSizeHints size_hints;
  245.       XSetWindowAttributes window_attributes;
  246. ***************
  247. *** 368,376 ****
  248.           exit(0);
  249.       }
  250.   
  251. -     xScreen = DefaultScreen(xDisplay);
  252.       XSetErrorHandler(XTiffErrorHandler);
  253.       XSynchronize(xDisplay, xSyncFlag);
  254.   
  255.       if (tfImageDepth != 1) {
  256.           template_visual.screen = xScreen;
  257. --- 372,380 ----
  258.           exit(0);
  259.       }
  260.   
  261.       XSetErrorHandler(XTiffErrorHandler);
  262.       XSynchronize(xDisplay, xSyncFlag);
  263. +     xScreen = DefaultScreen(xDisplay);
  264.   
  265.       if (tfImageDepth != 1) {
  266.           template_visual.screen = xScreen;
  267. ***************
  268. *** 386,392 ****
  269.       switch (tfImageDepth) {
  270.       /*
  271.        * X really wants a 32-bit image with the fourth channel unused,
  272. !      * but the visual structure thinks it's 24-bit.
  273.        */
  274.       case 32:
  275.       case 24:
  276. --- 390,396 ----
  277.       switch (tfImageDepth) {
  278.       /*
  279.        * X really wants a 32-bit image with the fourth channel unused,
  280. !      * but the visual structure thinks it's 24-bit.  bitmap_unit is 32.
  281.        */
  282.       case 32:
  283.       case 24:
  284. ***************
  285. *** 397,402 ****
  286. --- 401,407 ----
  287.           }
  288.   
  289.           colors = (XColor *) malloc(3 * colormapSize * sizeof(XColor));
  290. +         MCHECK(colors);
  291.   
  292.           for (i = 0; i < colormapSize; i++) {
  293.               colors[i].pixel = (u_long) (i << 16) + (i << 8) + i;
  294. ***************
  295. *** 420,431 ****
  296.           switch (tfPhotometricInterpretation) {
  297.           case PHOTOMETRIC_MINISWHITE:
  298.           case PHOTOMETRIC_MINISBLACK:
  299. -             /*
  300. -              * The VAX Firefox is broken here so PseudoColor is searched first.
  301. -              * The GrayScale visual doesn't seem to work.
  302. -              */
  303. -             if (SearchVisualList((int) tfImageDepth, PseudoColor, &xVisual))
  304. -                 break;
  305.               if (SearchVisualList((int) tfImageDepth, GrayScale, &xVisual))
  306.                   break;
  307.           case PHOTOMETRIC_PALETTE:
  308. --- 425,430 ----
  309. ***************
  310. *** 438,443 ****
  311. --- 437,443 ----
  312.           }
  313.   
  314.           colors = (XColor *) malloc(colormapSize * sizeof(XColor));
  315. +         MCHECK(colors);
  316.   
  317.           for (i = 0; i < colormapSize; i++) {
  318.               colors[i].pixel = (u_long) i;
  319. ***************
  320. *** 450,456 ****
  321.           /*
  322.            * xtiff's colormap allocation is private.  It does not attempt
  323.            * to detect whether any existing colormap entries are suitable
  324. !          * for its use.
  325.            */
  326.           xColormap = XCreateColormap(xDisplay, RootWindow(xDisplay, xScreen),
  327.               xVisual, AllocAll);
  328. --- 450,456 ----
  329.           /*
  330.            * xtiff's colormap allocation is private.  It does not attempt
  331.            * to detect whether any existing colormap entries are suitable
  332. !          * for its use.  This causes colormap flashing.
  333.            */
  334.           xColormap = XCreateColormap(xDisplay, RootWindow(xDisplay, xScreen),
  335.               xVisual, AllocAll);
  336. ***************
  337. *** 473,481 ****
  338.       window_attributes.event_mask = ExposureMask | ButtonPressMask;
  339.   
  340.       /*
  341. !      * win_width and win_height are not currently used.
  342.        */
  343. !     XParseGeometry(xGeometry, &win_x, &win_y, &win_width, &win_height);
  344.   
  345.       xWindow = XCreateWindow(xDisplay, RootWindow(xDisplay, xScreen),
  346.           win_x, win_y, tfImageWidth, tfImageHeight, border_width,
  347. --- 473,482 ----
  348.       window_attributes.event_mask = ExposureMask | ButtonPressMask;
  349.   
  350.       /*
  351. !      * win_w and win_h are not currently used.
  352.        */
  353. !     if (xGeometry != NULL)
  354. !         XParseGeometry(xGeometry, &win_x, &win_y, &win_w, &win_h);
  355.   
  356.       xWindow = XCreateWindow(xDisplay, RootWindow(xDisplay, xScreen),
  357.           win_x, win_y, tfImageWidth, tfImageHeight, border_width,
  358. ***************
  359. *** 495,508 ****
  360.           xtifficon_bits, xtifficon_width, xtifficon_height);
  361.   
  362.       size_hints.flags = PPosition | PSize | PMinSize | PMaxSize;
  363. !     size_hints.x = win_x;
  364. !     size_hints.y = win_y;
  365. !     size_hints.width = tfImageWidth;
  366. !     size_hints.height = tfImageHeight;
  367. !     size_hints.min_width = tfImageWidth;
  368. !     size_hints.min_height = tfImageHeight;
  369. !     size_hints.max_width = tfImageWidth;
  370. !     size_hints.max_height = tfImageHeight;
  371.   
  372.       XSetStandardProperties(xDisplay, xWindow, programName, programName,
  373.           xTiffIconPixmap, xargv, xargc, &size_hints);
  374. --- 496,506 ----
  375.           xtifficon_bits, xtifficon_width, xtifficon_height);
  376.   
  377.       size_hints.flags = PPosition | PSize | PMinSize | PMaxSize;
  378. !     size_hints.x = win_x; size_hints.y = win_y;
  379. !     size_hints.width = size_hints.min_width =
  380. !         size_hints.max_width = tfImageWidth;
  381. !     size_hints.height = size_hints.min_height =
  382. !         size_hints.max_height = tfImageHeight;
  383.   
  384.       XSetStandardProperties(xDisplay, xWindow, programName, programName,
  385.           xTiffIconPixmap, xargv, xargc, &size_hints);
  386. ***************
  387. *** 523,530 ****
  388.   
  389.       for (vis = xVisualList, i = 0; i < xNVisuals; vis++, i++) {
  390.           if ((vis->class == visual_class) && (vis->depth >= image_depth)) {
  391.               xImageDepth = vis->depth;
  392. !             xVisual = vis->visual;
  393.               return True;
  394.           }
  395.       }
  396. --- 521,531 ----
  397.   
  398.       for (vis = xVisualList, i = 0; i < xNVisuals; vis++, i++) {
  399.           if ((vis->class == visual_class) && (vis->depth >= image_depth)) {
  400. +             *visual = vis->visual;
  401.               xImageDepth = vis->depth;
  402. !             xRedMask = vis->red_mask;
  403. !             xGreenMask = vis->green_mask;
  404. !             xBlueMask = vis->blue_mask;
  405.               return True;
  406.           }
  407.       }
  408. ***************
  409. *** 535,542 ****
  410.   void
  411.   GetTIFFImage()
  412.   {
  413.       register int i, j, s;
  414. !     register u_char *scan_line, *output_p, *input_p, p;
  415.   
  416.       tfBytesPerRow = TIFFScanlineSize(tfFile);
  417.       scan_line = (u_char *) malloc(tfBytesPerRow);
  418. --- 536,544 ----
  419.   void
  420.   GetTIFFImage()
  421.   {
  422. +     register u_char *scan_line, *output_p, *input_p;
  423.       register int i, j, s;
  424. !     int pixel_map[3], red_shift, green_shift, blue_shift;
  425.   
  426.       tfBytesPerRow = TIFFScanlineSize(tfFile);
  427.       scan_line = (u_char *) malloc(tfBytesPerRow);
  428. ***************
  429. *** 543,561 ****
  430.       MCHECK(scan_line);
  431.   
  432.       if ((tfImageDepth == 32) || (tfImageDepth == 24)) {
  433. !         output_p = imageMemory =
  434. !             (u_char *) malloc(tfImageWidth * tfImageHeight * 4);
  435.           MCHECK(imageMemory);
  436.   
  437.           if (tfPlanarConfiguration == PLANARCONFIG_CONTIG) {
  438.               for (i = 0; i < tfImageHeight; i++) {
  439.                   if (TIFFReadScanline(tfFile, scan_line, i, 0) < 0)
  440.                       break;
  441.                   for (input_p = scan_line, j = 0; j < tfImageWidth; j++) {
  442. !                     *output_p++ = *input_p++;
  443. !                     *output_p++ = *input_p++;
  444. !                     *output_p++ = *input_p++;
  445. !                     output_p++;
  446.                       if (tfSamplesPerPixel == 4) /* skip the fourth channel */
  447.                           input_p++;
  448.                   }
  449. --- 545,573 ----
  450.       MCHECK(scan_line);
  451.   
  452.       if ((tfImageDepth == 32) || (tfImageDepth == 24)) {
  453. !         output_p = imageMemory = (u_char *)
  454. !             malloc(tfImageWidth * tfImageHeight * 4);
  455.           MCHECK(imageMemory);
  456.   
  457. +         /*
  458. +          * Handle different color masks for different frame buffers.
  459. +          */
  460. +         red_shift = pixel_map[0] = xRedMask == 0xFF000000 ? 3
  461. +             : (xRedMask == 0xFF0000 ? 2 : (xRedMask == 0xFF00 ? 1 : 0));
  462. +         green_shift = pixel_map[1] = xGreenMask == 0xFF000000 ? 3
  463. +             : (xGreenMask == 0xFF0000 ? 2 : (xGreenMask == 0xFF00 ? 1 : 0));
  464. +         blue_shift = pixel_map[2] = xBlueMask == 0xFF000000 ? 3
  465. +             : (xBlueMask == 0xFF0000 ? 2 : (xBlueMask == 0xFF00 ? 1 : 0));
  466.           if (tfPlanarConfiguration == PLANARCONFIG_CONTIG) {
  467.               for (i = 0; i < tfImageHeight; i++) {
  468.                   if (TIFFReadScanline(tfFile, scan_line, i, 0) < 0)
  469.                       break;
  470.                   for (input_p = scan_line, j = 0; j < tfImageWidth; j++) {
  471. !                     *(output_p + red_shift) = *input_p++;
  472. !                     *(output_p + green_shift) = *input_p++;
  473. !                     *(output_p + blue_shift) = *input_p++;
  474. !                     output_p += 4;
  475.                       if (tfSamplesPerPixel == 4) /* skip the fourth channel */
  476.                           input_p++;
  477.                   }
  478. ***************
  479. *** 568,574 ****
  480.                       if (TIFFReadScanline(tfFile, scan_line, i, s) < 0)
  481.                           break;
  482.                       input_p = scan_line;
  483. !                     output_p = imageMemory + (i * tfImageWidth * 4) + s;
  484.                       for (j = 0; j < tfImageWidth; j++, output_p += 4)
  485.                           *output_p = *input_p++;
  486.                   }
  487. --- 580,586 ----
  488.                       if (TIFFReadScanline(tfFile, scan_line, i, s) < 0)
  489.                           break;
  490.                       input_p = scan_line;
  491. !                     output_p = imageMemory + (i*tfImageWidth*4) + pixel_map[s];
  492.                       for (j = 0; j < tfImageWidth; j++, output_p += 4)
  493.                           *output_p = *input_p++;
  494.                   }
  495. ***************
  496. *** 581,588 ****
  497.            */
  498.           if ((tfPhotometricInterpretation == PHOTOMETRIC_MINISWHITE)
  499.               && (tfImageDepth == 1)) {
  500. !             output_p = imageMemory =
  501. !                 (u_char *) malloc(tfBytesPerRow * tfImageHeight);
  502.               MCHECK(imageMemory);
  503.   
  504.               for (i = 0; i < tfImageHeight; i++, output_p += tfBytesPerRow) {
  505. --- 593,600 ----
  506.            */
  507.           if ((tfPhotometricInterpretation == PHOTOMETRIC_MINISWHITE)
  508.               && (tfImageDepth == 1)) {
  509. !             output_p = imageMemory = (u_char *)
  510. !                 malloc(tfBytesPerRow * tfImageHeight);
  511.               MCHECK(imageMemory);
  512.   
  513.               for (i = 0; i < tfImageHeight; i++, output_p += tfBytesPerRow) {
  514. ***************
  515. *** 593,600 ****
  516.                       *input_p = ~ *input_p;
  517.               }
  518.           } else if (xImageDepth == tfImageDepth) {
  519. !             output_p = imageMemory =
  520. !                 (u_char *) malloc(tfBytesPerRow * tfImageHeight);
  521.               MCHECK(imageMemory);
  522.   
  523.               for (i = 0; i < tfImageHeight; i++, output_p += tfBytesPerRow)
  524. --- 605,612 ----
  525.                       *input_p = ~ *input_p;
  526.               }
  527.           } else if (xImageDepth == tfImageDepth) {
  528. !             output_p = imageMemory = (u_char *)
  529. !                 malloc(tfBytesPerRow * tfImageHeight);
  530.               MCHECK(imageMemory);
  531.   
  532.               for (i = 0; i < tfImageHeight; i++, output_p += tfBytesPerRow)
  533. ***************
  534. *** 601,608 ****
  535.                   if (TIFFReadScanline(tfFile, output_p, i, 0) < 0)
  536.                       break;
  537.           } else if ((xImageDepth == 8) && (tfImageDepth == 4)) {
  538. !             output_p = imageMemory =
  539. !                 (u_char *) malloc(tfBytesPerRow * 2 * tfImageHeight + 2);
  540.               MCHECK(imageMemory);
  541.   
  542.               /*
  543. --- 613,620 ----
  544.                   if (TIFFReadScanline(tfFile, output_p, i, 0) < 0)
  545.                       break;
  546.           } else if ((xImageDepth == 8) && (tfImageDepth == 4)) {
  547. !             output_p = imageMemory = (u_char *)
  548. !                 malloc(tfBytesPerRow * 2 * tfImageHeight + 2);
  549.               MCHECK(imageMemory);
  550.   
  551.               /*
  552. ***************
  553. *** 616,628 ****
  554.                   output_p = &imageMemory[i * tfImageWidth];
  555.                   input_p = scan_line;
  556.                   for (j = 0; j < tfImageWidth; j += 2, input_p++) {
  557. !                     *output_p++ = (*input_p) >> 4;
  558. !                     *output_p++ = (*input_p) & 0xf;
  559.                   }
  560.               }
  561.           } else if ((xImageDepth == 8) && (tfImageDepth == 2)) {
  562. !             output_p = imageMemory =
  563. !                 (u_char *) malloc(tfBytesPerRow * 4 * tfImageHeight + 4);
  564.               MCHECK(imageMemory);
  565.   
  566.               for (i = 0; i < tfImageHeight; i++) {
  567. --- 628,640 ----
  568.                   output_p = &imageMemory[i * tfImageWidth];
  569.                   input_p = scan_line;
  570.                   for (j = 0; j < tfImageWidth; j += 2, input_p++) {
  571. !                     *output_p++ = *input_p >> 4;
  572. !                     *output_p++ = *input_p & 0xf;
  573.                   }
  574.               }
  575.           } else if ((xImageDepth == 8) && (tfImageDepth == 2)) {
  576. !             output_p = imageMemory = (u_char *)
  577. !                 malloc(tfBytesPerRow * 4 * tfImageHeight + 4);
  578.               MCHECK(imageMemory);
  579.   
  580.               for (i = 0; i < tfImageHeight; i++) {
  581. ***************
  582. *** 638,645 ****
  583.                   }
  584.               }
  585.           } else if ((xImageDepth == 4) && (tfImageDepth == 2)) {
  586. !             output_p = imageMemory =
  587. !                 (u_char *) malloc(tfBytesPerRow * 2 * tfImageHeight + 2);
  588.               MCHECK(imageMemory);
  589.   
  590.               for (i = 0; i < tfImageHeight; i++) {
  591. --- 650,657 ----
  592.                   }
  593.               }
  594.           } else if ((xImageDepth == 4) && (tfImageDepth == 2)) {
  595. !             output_p = imageMemory = (u_char *)
  596. !                 malloc(tfBytesPerRow * 2 * tfImageHeight + 2);
  597.               MCHECK(imageMemory);
  598.   
  599.               for (i = 0; i < tfImageHeight; i++) {
  600. ***************
  601. *** 648,655 ****
  602.                   output_p = &imageMemory[i * tfImageWidth];
  603.                   input_p = scan_line;
  604.                   for (j = 0; j < tfImageWidth; j += 4, input_p++) {
  605. !                     *output_p++ = ((*input_p >> 6) << 4) | (*input_p >> 4) & 3;
  606. !                     *output_p++ = (((*input_p >> 2) & 3) << 4) | *input_p & 3;
  607.                   }
  608.               }
  609.           } else {
  610. --- 660,667 ----
  611.                   output_p = &imageMemory[i * tfImageWidth];
  612.                   input_p = scan_line;
  613.                   for (j = 0; j < tfImageWidth; j += 4, input_p++) {
  614. !                     *output_p++ = ((*input_p>>6) << 4) | ((*input_p >> 4) & 3);
  615. !                     *output_p++ = (((*input_p>>2) & 3) << 4) | (*input_p & 3);
  616.                   }
  617.               }
  618.           } else {
  619. ***************
  620. *** 677,704 ****
  621.       /*
  622.        * libtiff converts LSB data into MSB but doesn't change the FillOrder tag.
  623.        */
  624. !     xImage->bitmap_bit_order = MSBFirst;
  625.       if (xImageDepth <= 8)
  626.           xImage->byte_order = MSBFirst;
  627. -     else
  628. -         xImage->byte_order = xVisual->red_mask > xVisual->blue_mask
  629. -             ? LSBFirst : MSBFirst;
  630.   
  631. -     /*
  632. -      * According to the O'Reilly X Protocol Reference Manual, page 53,
  633. -      * "A pixmap depth of one is always supported and listed, but windows
  634. -      * of depth one might not be supported."  Therefore we create a pixmap
  635. -      * of depth one and use XCopyPlane().
  636. -      */
  637.       if (xPixmapFlag == True) {
  638.           xImagePixmap = XCreatePixmap(xDisplay, RootWindow(xDisplay, xScreen),
  639.               xImage->width, xImage->height, xImageDepth);
  640.   
  641.           if (xImageDepth == 1) {
  642. !             xBitmapGc = XCreateGC(xDisplay, xImagePixmap,
  643. !                 GCFunction | GCPlaneMask | GCForeground | GCBackground,
  644. !                 &xGcValues);
  645.               XPutImage(xDisplay, xImagePixmap, xBitmapGc, xImage,
  646.                   0, 0, 0, 0, xImage->width, xImage->height);
  647.           } else
  648. --- 689,712 ----
  649.       /*
  650.        * libtiff converts LSB data into MSB but doesn't change the FillOrder tag.
  651.        */
  652. !     if (xImageDepth == 1)
  653. !         xImage->bitmap_bit_order = MSBFirst;
  654.       if (xImageDepth <= 8)
  655.           xImage->byte_order = MSBFirst;
  656.   
  657.       if (xPixmapFlag == True) {
  658.           xImagePixmap = XCreatePixmap(xDisplay, RootWindow(xDisplay, xScreen),
  659.               xImage->width, xImage->height, xImageDepth);
  660.   
  661. +         /*
  662. +          * According to the O'Reilly X Protocol Reference Manual, page 53,
  663. +          * "A pixmap depth of one is always supported and listed, but windows
  664. +          * of depth one might not be supported."  Therefore we create a pixmap
  665. +          * of depth one and use XCopyPlane().  This is idiomatic.
  666. +          */
  667.           if (xImageDepth == 1) {
  668. !             xBitmapGc = XCreateGC(xDisplay, xImagePixmap, GCFunction
  669. !                 | GCPlaneMask | GCForeground | GCBackground, &xGcValues);
  670.               XPutImage(xDisplay, xImagePixmap, xBitmapGc, xImage,
  671.                   0, 0, 0, 0, xImage->width, xImage->height);
  672.           } else
  673. ***************
  674. *** 706,714 ****
  675.                   0, 0, 0, 0, xImage->width, xImage->height);
  676.           XDestroyImage(xImage);
  677.       }
  678. -     if (xPixmapFlag == True)
  679. -         free(imageMemory);
  680.   
  681.       if (grayMap != NULL)
  682.           free(grayMap);
  683. --- 714,719 ----
  684. diff -r -c rev1/xtiff.man rev2/xtiff.man
  685. *** rev1/xtiff.man    Wed May 16 12:33:39 1990
  686. --- rev2/xtiff.man    Thu May 17 11:16:27 1990
  687. ***************
  688. *** 24,30 ****
  689.   .IR file
  690.   .SH DESCRIPTION
  691.   .IR xtiff
  692. ! is a TIFF viewer for X-based on the
  693.   .IR libtiff (3)
  694.   package.
  695.   It displays a single TIFF file in an X window
  696. --- 24,30 ----
  697.   .IR file
  698.   .SH DESCRIPTION
  699.   .IR xtiff
  700. ! is a TIFF viewer for X based on the
  701.   .IR libtiff (3)
  702.   package.
  703.   It displays a single TIFF file in an X window
  704. ***************
  705. *** 162,164 ****
  706. --- 162,165 ----
  707.   or
  708.   .IR TrueColor
  709.   visuals except for 1-bit images.
  710. + There is no support for 3/3/2 DirectColor visuals.
  711.  
  712. dan
  713. ----------------------------------------------------
  714. O'Reilly && Associates   argv@sun.com / argv@ora.com
  715. Opinions expressed reflect those of the author only.
  716.